<?php
	/* Functions in this file */
	/**************************/

	// GetGuitars($rhythmSlashes)
	// GetMFCClassName()
	// GetMFCClassSchema()
	// GetPosition()
	// GetRhythmSlashGuitars()
	// GetStaff()
	// GetStaffGuitars()
	// GetSystem()
	// GetText($rhythmSlashes)
	// HasGuitarsSet($rhythmSlashes)
	// HasRhythmSlashGuitarsSet()
	// HasStaffGuitarsSet()
	// IsValidPosition($position)
	// IsValidStaff($staff)
	// IsValidSystem($system)
	// SetPosition($position)
	// SetRhythmSlashGuitars($guitars)
	// SetStaff($staff)
	// SetStaffGuitars($guitars)
	// SetSystem($system)
?>
<?php
	 
	 
	class GuitarIn {
		 
		 
		// Constants
		 
		// Default constants
		const DEFAULT_SYSTEM = 0;
		const DEFAULT_STAFF = 0;
		const DEFAULT_POSITION = 0;
		const DEFAULT_DATA = 0;
		 
		// System Constants
		const MIN_SYSTEM = 0;
		const MAX_SYSTEM = 65535;
		 
		// Staff Constants
		const MIN_STAFF = 0;
		const MAX_STAFF = 2;
		 
		// Position Constants
		const MIN_POSITION = 0;
		const MAX_POSITION = 255;
		 
		 
		protected $m_system = self::DEFAULT_SYSTEM;
		protected $m_staff = self::DEFAULT_STAFF;
		protected $m_position = self::DEFAULT_POSITION;
		protected $m_data = self::DEFAULT_DATA;
		 
		// Creation Functions
		 
		 
		 
		// MFC Class Functions
		function GetMFCClassName() {
			return "CGuitarIn";
		}
		function GetMFCClassSchema() {
			return 1;
		}
		 
		// System Functions
		 
		 
		 
		function IsValidSystem($system) {
			return (($system >= self::MIN_SYSTEM) && ($system <= self::MAX_SYSTEM));
		}
		 
		 
		 
		function SetSystem($system) {
			if (!$this->IsValidSystem($system)) return 0;
			$this->m_system = $system;
			 return 1;
		}
		 
		 
		function GetSystem() {
			return ($this->m_system);
		}
		 
		// Staff Functions
		 
		 
		 
		function IsValidStaff($staff) {
			return (($staff >= self::MIN_STAFF) && ($staff <= self::MAX_STAFF));
		}
		 
		 
		 
		function SetStaff($staff) {
			if (!$this->IsValidStaff($staff)) return 0;
			$this->m_staff = $staff;
			 return 1;
		}
		 
		 
		function GetStaff() {
			return ($this->m_staff);
		}
		 
		// Position Functions
		 
		 
		 
		function IsValidPosition($position) {
			return (($position >= self::MIN_POSITION) && ($position <= self::MAX_POSITION));
		}
		 
		 
		 
		function SetPosition($position) {
			if (!$this->IsValidPosition($position)) return 0;
			$this->m_position = $position;
			 return 1;
		}
		 
		 
		function GetPosition() {
			return ($this->m_position);
		}
		 
		// Staff Guitars Functions
		 
		 
		 
		function SetStaffGuitars($guitars) {
			return ($this->SetGuitars(0, $guitars));
		}
		 
		 
		function GetStaffGuitars() {
			return ($this->GetGuitars(0));
		}
		 
		 
		function HasStaffGuitarsSet() {
			return ($this->HasGuitarsSet(0));
		}
		 
		// Rhythm Slash Functions
		 
		 
		 
		function SetRhythmSlashGuitars($guitars) {
			return ($this->SetGuitars(true, $guitars));
		}
		 
		 
		function GetRhythmSlashGuitars() {
			return ($this->GetGuitars(1));
		}
		 
		 
		function HasRhythmSlashGuitarsSet() {
			return ($this->HasGuitarsSet(1));
		}
		 
		 
		 
		function GuitarIn($system = NULL, $staff = NULL, $position = NULL, $staffGuitars = NULL, $rhythmSlashGuitars = NULL) {
			 
			//------Last Checked------//
			// - Jan 25, 2005
			if (!$this->IsValidSystem($system)) return 0;
			if (!$this->IsValidStaff($staff)) return 0;
			if (!$this->IsValidPosition($position)) return 0;
			$this->SetSystem($system);
			$this->SetStaff($staff);
			$this->SetPosition($position);
			$this->SetStaffGuitars($staffGuitars);
			$this->SetRhythmSlashGuitars($rhythmSlashGuitars);
		}
		 
		 
		// Serialize Functions
		 
		function DoSerialize(&$stream){
		 
			WRITE_WORD ($stream,$this->m_system);
			WRITE_BYTE ($stream,$this->m_staff);
			WRITE_BYTE ($stream,$this->m_position);
			WRITE_WORD ($stream,$this->m_data);

			return 1;
		}
		
		 
		function DoDeserialize(&$stream){
		 
			$this->m_system = READ_WORD ($stream);
			$this->m_staff = READ_BYTE ($stream);
			$this->m_position = READ_BYTE ($stream);
			$this->m_data = READ_WORD ($stream);
		
		}
		 
		// Guitars Functions
		
		 
		 
		 
		function SetGuitars($rhythmSlashes, $guitars) {
			 
			//------Last Checked------//
			// - Jan 25, 2005
			if ($rhythmSlashes)
				$this->m_data = MAKEWORD($guitars, $this->GetStaffGuitars());
			else
				$this->m_data = MAKEWORD($this->GetRhythmSlashGuitars(), $guitars);
			 
			return 1;
		}
		 
		 
		 
		 
		function GetGuitars($rhythmSlashes) {
			 
			//------Last Checked------//
			// - Jan 25, 2005
			if ($rhythmSlashes)
				return (LOBYTE($this->m_data));
			return (HIBYTE($this->m_data));
		}
		 
		 
		 
		 
		function HasGuitarsSet($rhythmSlashes) {
			 
			//------Last Checked------//
			// - Jan 25, 2005
			$guitars = (($rhythmSlashes) ? $this->GetRhythmSlashGuitars() : $this->GetStaffGuitars());
			return ($guitars != 0);
		}
		 
		// Operations
		 
		 
		 
		function GetText($rhythmSlashes) {
			 
			//------Last Checked------//
			// - Jan 25, 2005
			$guitars = $this->GetGuitars($rhythmSlashes);
			 
			if ($guitars == 0)
				return "";
			
			$returnValue;
			$romanNumerals;
			 
			// Loop through, add $guitars as we go - there are only 7 $guitars
			$mask = 1;
			$guitarCount = 0;
			$guitarNumber = 1;
			for (; ; $mask *= 2, $guitarNumber++) {
				 
				// Guitar is set
				if (($guitars & $mask) == $mask) {
					 
					// Add a comma if we already have a numeral
					if (isset($romanNumerals))
						$romanNumerals .= ", ";
					 
					// Add the roman numeral
					$romanNumerals .= $this->ArabicToRoman($guitarNumber, 1);
					$guitarCount++;
				}
				 
				// block overflow
				if ($mask == 64)
					break;
			}
			 
			// Add the symbol Gtr before
			if ($guitarCount == 1)
				$returnValue = sprintf("Gtr %s", $romanNumerals);
			else
				$returnValue = sprintf("Gtrs %s", $romanNumerals);
			 
			return ($returnValue);
		}
		 
		function ArabicToRoman($number, $upperCase) {
			 
			//------Last Checked------//
			// - Dec 7, 2004
			 
			// Can only convert 1 to 5999
			if (!(($number > 0) && ($number < 6000))) return "";
			 
			$returnValue;
			while ($number >= 1000) {
				$number -= 1000;
				 $returnValue .= "m";
			}
			while ($number >= 900) {
				$number -= 900;
				 $returnValue .= "cm";
			}
			while ($number >= 500) {
				$number -= 500;
				 $returnValue .= "d";
			}
			while ($number >= 400) {
				$number -= 400;
				 $returnValue .= "cd";
			}
			while ($number >= 100) {
				$number -= 100;
				 $returnValue .= "c";
			}
			while ($number >= 90) {
				$number -= 90;
				 $returnValue .= "xc";
			}
			while ($number >= 50) {
				$number -= 50;
				 $returnValue .= "l";
			}
			while ($number >= 40) {
				$number -= 40;
				 $returnValue .= "xl";
			}
			while ($number >= 10) {
				$number -= 10;
				 $returnValue .= "x";
			}
			while ($number >= 9) {
				$number -= 9;
				 $returnValue .= "ix";
			}
			while ($number >= 5) {
				$number -= 5;
				 $returnValue .= "v";
			}
			while ($number >= 4) {
				$number -= 4;
				 $returnValue .= "iv";
			}
			while ($number >= 1) {
				$number -= 1;
				 $returnValue .= "i";
			}
			 
			// Force the text to upper case
			if ($upperCase)
				$returnValue = strtoupper($returnValue);

			 
			return ($returnValue);
		}
		 
	}
	 
?>

